//go:build ignore

package main

import (
	"bytes"
	"fmt"
	"io"
	"mime/multipart"
	"net/http"
	"os"
)

func uploadTest() {
	filename := fmt.Sprintf("file_%d", 1)

	file, err := os.Create(filename)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	_, err = file.Write([]byte("hello"))
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	bodyBuf := &bytes.Buffer{}
	bodyWriter := multipart.NewWriter(bodyBuf)
	fileWriter, err := bodyWriter.CreateFormFile("files", filename)
	if err != nil {
		fmt.Println("error writing to buffer")
		return
	}
	_, err = io.Copy(fileWriter, file)
	if err != nil {
		return
	}

	contentType := bodyWriter.FormDataContentType()
	err = bodyWriter.Close()
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	resp, err := http.Post("http://127.0.0.1:9999/api/fileupload", contentType, bodyBuf)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	defer func(Body io.ReadCloser) {
		err := Body.Close()
		if err != nil {
			fmt.Println(err.Error())
			return
		}
	}(resp.Body)

}

func main() {
	uploadTest()
}
